﻿using NLog;
using NLog.Config;
using PeterKottas.DotNetCore.WindowsService;
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;

namespace ColorCMS.Service
{
    class Program
    {

        static void Main(string[] args)
        {
            ServiceRunner<Service>.Run(config =>
            {
                config.SetName("ColorCMS");
                config.SetDescription("Colorful CMS Service");
                config.SetDisplayName("ColorCMS");
                var name = config.GetDefaultName();
                config.Service(serviceConfig =>
                {
                    LogManager.Configuration = new XmlLoggingConfiguration($"{AppContext.BaseDirectory}NLog.config");
                    var logger = LogManager.GetLogger("Program");
                    serviceConfig.ServiceFactory((extraArguments, controller) =>
                    {
                        return new Service();
                    });
                    serviceConfig.OnStart((service, extraArguments) =>
                    {
                        logger.Info("Service {0} started", name);
                        service.Start();
                    });

                    serviceConfig.OnStop(service =>
                    {
                        logger.Info("Service {0} stopped", name);
                        service.Stop();
                    });

                    serviceConfig.OnError(e =>
                    {
                        logger.Info("Service {0} errored with exception : {1}", name, e.Message);
                    });
                });
            });
        }
    }
}
